﻿using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Microsoft.Phone.Controls;
using SydEnergiPrototype.Kernel;
using SydEnergiPrototype.ViewModel;

namespace SydEnergiPrototype.View
{
    public partial class FinalizeEditView : PhoneApplicationPage
    {
        public IFinalizeEditViewModel ViewModel;
        public FinalizeEditView()
        {
            InitializeComponent();
            ViewModel = IoCContainer.Get<IFinalizeEditViewModel>();
            LayoutRoot.DataContext = ViewModel;

            this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);

            InitializeReasonPanel();
        }

        private void InitializeReasonPanel()
        {
            foreach (var reason in ViewModel.Reasons)
            {
                var radio = new RadioButton();
                radio.Content = reason;
                radio.Margin = new Thickness(0,-5,0,-20);
                radio.Checked += UpdateSelectedItem;

                if(ViewModel.Reasons.IndexOf(reason) == 0)
                    radio.IsChecked = true;

                ReasonPanel.Children.Add(radio);
            }
        }

        private void UpdateSelectedItem(object sender, RoutedEventArgs e)
        {
            var button = sender as RadioButton;
            ViewModel.SelectedReason = button.Content.ToString();
        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/FindCabinetView.xaml", UriKind.Relative));
        }
    }
}